package leetcode.code0817;

import java.util.HashSet;
import java.util.Set;

import leetcode.IDebug;
import leetcode.helper.tree.ListNode;

public class Solution implements IDebug {

	public int numComponents(ListNode head, int[] nums) {
		Set<Integer> set = new HashSet<>();
		for (int num : nums) {
			set.add(num);
		}
		int ans = 0;
		while (head != null) {
			while (head != null && !set.contains(head.val)) {
				head = head.next;
			}
			if (head != null)
				ans += 1;
			while (head != null && set.contains(head.val)) {
				head = head.next;
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
